<!DOCTYPE html>
<html><head>
	<meta charset="UTF-8">
	<meta http-equiv="x-UA-Compatible" content="ie=Edge">
   	<meta name="viewport" content="width=device-width, initial-scale=1">
   	<title>Crafty - Crafty.math.Vector2D</title>
	<link type="text/css" rel="stylesheet" href="../craftyjs-site.css">
	<link rel="shortcut icon" href="../favicon.ico">
</head>
<body>
	<div id="header-background"> </div>
	<div id="page-frame">
	<div id="header">
		<nav class="navbar">
  			<div class="container-fluid">
  				<div class="navbar-header">
  					<a class="navbar-brand" href="../"> <img class="logo" src="../images/text-logo.png"> </a>
  					
				</div>
				<div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
					<ul class="nav navbar-nav">
						<li><a href="../">首页</a></li>
						<li><a href="../getting-started/">快速开始</a></li>
						<li><a href="../documentation/">文档</a></li>
						<li><a href="../api/">API</a></li>
						<li><a href="../components/">组件</a></li>
						<li class="emph"><a href="../#install">下载</a></li>
					</ul>
				</div>
			</div>
		</nav>
	</div>


	<div id="main">
		<div id="content" class="container">
			



<div id="docs"><div class="toc-holder" id="doc-nav"><ul id="doc-level-one"><li><a href="events.html">事件列表</a></li><li class="category">核心<ul class="category-list"><li><a href="Crafty.html">Crafty</a></li><li><a href="Crafty Core.html">Crafty Core</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-c.html">Crafty.c()</a></li><li><a href="Crafty-clone.html">Crafty.clone()</a></li><li><a href="Crafty-defineField.html">Crafty.defineField()</a></li><li><a href="Crafty-e.html">Crafty.e()</a></li><li><a href="Crafty-extend.html">Crafty.extend()</a></li><li><a href="Crafty-frame.html">Crafty.frame()</a></li><li><a href="Crafty-getVersion.html">Crafty.getVersion()</a></li><li><a href="Crafty-init.html">Crafty.init()</a></li><li><a href="Crafty-isPaused.html">Crafty.isPaused()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-pause.html">Crafty.pause()</a></li><li><a href="Crafty-s.html">Crafty.s()</a></li><li><a href="Crafty-settings.html">Crafty.settings</a></li><li><a href="Crafty-stage.html">Crafty.stage</a></li><li><a href="Crafty-stop.html">Crafty.stop()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">2D<ul class="category-list"><li><a href="2D.html">2D</a></li><li><a href="AngularMotion.html">AngularMotion</a></li><li><a href="Collision.html">Collision</a></li><li><a href="Crafty-circle.html">Crafty.circle</a></li><li><a href="Crafty-diamondIso.html">Crafty.diamondIso</a></li><li><a href="Crafty-HashMap.html">Crafty.HashMap</a></li><li><a href="Crafty-isometric.html">Crafty.isometric</a></li><li><a href="Crafty-map.html">Crafty.map</a></li><li><a href="Crafty-math-Matrix2D.html">Crafty.math.Matrix2D</a></li><li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li><li><a href="Crafty-polygon.html">Crafty.polygon</a></li><li><a href="Crafty-raycast.html">Crafty.raycast()</a></li><li><a href="Crafty-rectManager.html">Crafty.rectManager</a></li><li><a href="Gravity.html">Gravity</a></li><li><a href="GroundAttacher.html">GroundAttacher</a></li><li><a href="Motion.html">Motion</a></li><li><a href="Supportable.html">Supportable</a></li></ul></li><li class="category">动画<ul class="category-list"><li><a href="Crafty-easing.html">Crafty.easing</a></li><li><a href="SpriteAnimation.html">SpriteAnimation</a></li><li><a href="Tween.html">Tween</a></li></ul></li><li class="category">资源<ul class="category-list"><li><a href="Crafty-asset.html">Crafty.asset()</a></li><li><a href="Crafty-assets.html">Crafty.assets</a></li><li><a href="Crafty-imageWhitelist.html">Crafty.imageWhitelist()</a></li><li><a href="Crafty-load.html">Crafty.load()</a></li><li><a href="Crafty-paths.html">Crafty.paths()</a></li><li><a href="Crafty-removeAssets.html">Crafty.removeAssets()</a></li></ul></li><li class="category">音频<ul class="category-list"><li><a href="Crafty-audio.html">Crafty.audio</a></li></ul></li><li class="category">控制器<ul class="category-list"><li><a href="Controllable.html">Controllable</a></li><li><a href="Controls.html">Controls</a></li><li><a href="Draggable.html">Draggable</a></li><li><a href="Fourway.html">Fourway</a></li><li><a href="Jumper.html">Jumper</a></li><li><a href="Multiway.html">Multiway</a></li><li><a href="Twoway.html">Twoway</a></li></ul></li><li class="category">调试<ul class="category-list"><li><a href="Crafty-error.html">Crafty.error()</a></li><li><a href="Crafty-log.html">Crafty.log()</a></li><li><a href="DebugCanvas.html">DebugCanvas</a></li><li><a href="DebugPolygon.html">DebugPolygon</a></li><li><a href="DebugRectangle.html">DebugRectangle</a></li><li><a href="SolidAreaMap.html">SolidAreaMap</a></li><li><a href="SolidHitBox.html">SolidHitBox</a></li><li><a href="VisibleMBR.html">VisibleMBR</a></li><li><a href="WiredAreaMap.html">WiredAreaMap</a></li><li><a href="WiredHitBox.html">WiredHitBox</a></li></ul></li><li class="category">事件<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">游戏循环<ul class="category-list"><li><a href="Crafty-timer.html">Crafty.timer</a></li></ul></li><li class="category">图形<ul class="category-list"><li><a href="Canvas.html">Canvas</a></li><li><a href="CanvasLayer.html">CanvasLayer</a></li><li><a href="Color.html">Color</a></li><li><a href="Crafty-assignColor.html">Crafty.assignColor()</a></li><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-createLayer.html">Crafty.createLayer()</a></li><li><a href="Crafty-defaultShader.html">Crafty.defaultShader()</a></li><li><a href="Crafty-domHelper.html">Crafty.domHelper</a></li><li><a href="Crafty-pixelart.html">Crafty.pixelart()</a></li><li><a href="Crafty-sprite.html">Crafty.sprite()</a></li><li><a href="Crafty-WebGLShader.html">Crafty.WebGLShader()</a></li><li><a href="DOM.html">DOM</a></li><li><a href="DomLayer.html">DomLayer</a></li><li><a href="HTML.html">HTML</a></li><li><a href="Image.html">Image</a></li><li><a href="Particles.html">Particles</a></li><li><a href="Renderable.html">Renderable</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="Text.html">Text</a></li><li><a href="WebGL.html">WebGL</a></li><li><a href="WebGLLayer.html">WebGLLayer</a></li></ul></li><li class="category">输入<ul class="category-list"><li><a href="AreaMap.html">AreaMap</a></li><li><a href="Button.html">Button</a></li><li><a href="Crafty-findPointerEventTargetByComponent.html">Crafty.findPointerEventTargetByComponent()</a></li><li><a href="Crafty-keyboardDispatch.html">Crafty.keyboardDispatch()</a></li><li><a href="Crafty-keydown.html">Crafty.keydown</a></li><li><a href="Crafty-keys.html">Crafty.keys</a></li><li><a href="Crafty-lastEvent.html">Crafty.lastEvent</a></li><li><a href="Crafty-mouseButtons.html">Crafty.mouseButtons</a></li><li><a href="Crafty-mouseDispatch.html">Crafty.mouseDispatch()</a></li><li><a href="Crafty-mouseWheelDispatch.html">Crafty.mouseWheelDispatch()</a></li><li><a href="Crafty-multitouch.html">Crafty.multitouch()</a></li><li><a href="Crafty-selected.html">Crafty.selected</a></li><li><a href="Crafty-touchDispatch.html">Crafty.touchDispatch()</a></li><li><a href="Keyboard.html">Keyboard</a></li><li><a href="Mouse.html">Mouse</a></li><li><a href="MouseDrag.html">MouseDrag</a></li><li><a href="Touch.html">Touch</a></li></ul></li><li class="category">杂项<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-device.html">Crafty.device</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li></ul></li><li class="category">模型<ul class="category-list"><li><a href="Model.html">Model</a></li></ul></li><li class="category">场景<ul class="category-list"><li><a href="Crafty-scene.html">Crafty.scene()</a></li></ul></li><li class="category">舞台<ul class="category-list"><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-scene.html">Crafty.scene()</a></li><li><a href="Crafty-viewport.html">Crafty.viewport</a></li></ul></li><li class="category">工具<ul class="category-list"><li><a href="Crafty-math.html">Crafty.math</a></li><li><a href="Delay.html">Delay</a></li><li><a href="Storage.html">Storage</a></li></ul></li></ul></div><div id="doc-content" class="doc-page-holder"><div class="doc-page"><h1>Crafty.math.Vector2D <span class="page-badge">类</span></h1><div class="doclet" id="Crafty-math-Vector2D"><span class="markdown"><p>Vector2D 使用方式如下:</p>
<x, y="">
</x,></span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Number</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D|Number=0} x </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Number=0} y </dt><dd><span class="markdown"></span></dd></dl></div></div><div><h4>方法</h4><ul class="page-toc"><li><a href="#-add">.add()</a></li><li><a href="#-angleBetween">.angleBetween()</a></li><li><a href="#-angleTo">.angleTo()</a></li><li><a href="#-clone">.clone()</a></li><li><a href="#-crossProduct">.crossProduct()</a></li><li><a href="#-distance">.distance()</a></li><li><a href="#-distanceSq">.distanceSq()</a></li><li><a href="#-divide">.divide()</a></li><li><a href="#-dotProduct">.dotProduct()</a></li><li><a href="#-equals">.equals()</a></li><li><a href="#-getNormal">.getNormal()</a></li><li><a href="#-isZero">.isZero()</a></li><li><a href="#-magnitude">.magnitude()</a></li><li><a href="#-magnitudeSq">.magnitudeSq()</a></li><li><a href="#-multiply">.multiply()</a></li><li><a href="#-negate">.negate()</a></li><li><a href="#-normalize">.normalize()</a></li><li><a href="#-perpendicular">.perpendicular()</a></li><li><a href="#-scale">.scale()</a></li><li><a href="#-scaleToMagnitude">.scaleToMagnitude()</a></li><li><a href="#-setValues">.setValues()</a></li><li><a href="#-subtract">.subtract()</a></li><li><a href="#-toString">.toString()</a></li><li><a href="#-translate">.translate()</a></li><li><a href="#-tripleProduct">.tripleProduct()</a></li></ul><div class="doclet" id="-add"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.add()</h2><span class="markdown"><p>将传递的向量添加到这个向量</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">add</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D}是之后要添加的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-angleBetween"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.angleBetween()</h2><span class="markdown"><p>计算传递向量与这个向量之间的夹角，使用&lt;0,0&gt;作为参考点。返回的角度在这个范围 (−π, π].</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">angleBetween</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} 是两个向量的夹角</p>
</span></dd></dl></div></div><div class="doclet" id="-angleTo"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.angleTo()</h2><span class="markdown"><p>计算从这个向量得到传递向量的角度，用这个向量作为参考点。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">angleTo</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} 两个向量的夹角弧度</p>
</span></dd></dl></div></div><div class="doclet" id="-clone"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.clone()</h2><span class="markdown"><p>创建并获取，这个矢量的数值拷贝</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">clone</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 是新的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-crossProduct"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.crossProduct()</h2><span class="markdown"><p>计算两个向量的外积的z分量，这两个向量的积是三维的</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">crossProduct</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} 是合成的外积</p>
</span></dd></dl></div></div><div class="doclet" id="-distance"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.distance()</h2><span class="markdown"><p>计算从这个向量到传递向量的距离。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">distance</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} 是两个向量间的距离</p>
</span></dd></dl></div></div><div class="doclet" id="-distanceSq"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.distanceSq()</h2><span class="markdown"><p>计算从这个向量到传递向量的平方距离。这个函数避免计算平方根，因此比 .distance( ) 略快。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">distanceSq</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} 两个矢量之间距离的平方</p>
</span></dd></dl></div><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-distance">.distance</a></li></ul></div></div><div class="doclet" id="-divide"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.divide()</h2><span class="markdown"><p>将这个向量除以传递的向量。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">divide</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 被除后的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-dotProduct"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.dotProduct()</h2><span class="markdown"><p>计算这个和经过的向量的点积</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">dotProduct</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} 为最终的点积</p>
</span></dd></dl></div></div><div class="doclet" id="-equals"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.equals()</h2><span class="markdown"><p>确定这个向量在数值上与传递的向量是否等价。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Boolean} </span><span class="sig-noun">equals</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Boolean} true 如果两个向量相等</p>
</span></dd></dl></div></div><div class="doclet" id="-getNormal"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.getNormal()</h2><span class="markdown"><p>计算一个新的右向单位向量，它垂直于由这个和传递的向量所创建的直线。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">getNormal</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Vector2D} [result] </dt><dd><span class="markdown"><p>可选参数，用来保存结果</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 新的标准向量</p>
</span></dd></dl></div></div><div class="doclet" id="-isZero"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.isZero()</h2><span class="markdown"><p>确定这个向量是否等于&lt;0,0&gt;</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Boolean} </span><span class="sig-noun">isZero</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Boolean} true 如果这个向量等于 &lt;0,0&gt;</p>
</span></dd></dl></div></div><div class="doclet" id="-magnitude"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.magnitude()</h2><span class="markdown"><p>计算这个向量的大小。注意:JavaScript中的函数对象已经有一个“length”成员，因此使用的是数量级。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">magnitude</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} 这个矢量的大小</p>
</span></dd></dl></div></div><div class="doclet" id="-magnitudeSq"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.magnitudeSq()</h2><span class="markdown"><p>计算这个向量的大小的平方。这个函数避免计算平方根，因此比 .magnitude( ) 略快。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Number} </span><span class="sig-noun">magnitudeSq</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Number} 这个矢量的大小的平方</p>
</span></dd></dl></div><div><h4>参见</h4><ul class="see-also-list"><li><a href="#-magnitude">.magnitude</a></li></ul></div></div><div class="doclet" id="-multiply"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.multiply()</h2><span class="markdown"><p>使用传递向量乘以这个向量</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">multiply</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 向量的乘积</p>
</span></dd></dl></div></div><div class="doclet" id="-negate"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.negate()</h2><span class="markdown"><p>向量取反 (例如， &lt;-x,-y&gt;)</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">negate</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 取反后的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-normalize"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.normalize()</h2><span class="markdown"><p>归一化向量(缩放这个向量使它新的大小为 1)
对于大小为0的向量, 返回 &lt;1,0&gt;。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">normalize</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 归一化之后的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-perpendicular"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.perpendicular()</h2><span class="markdown"><p>计算一个垂直于这个向量的新向量。垂直向量与这个向量的大小相同，将这个向量逆时针旋转90度得到新向量。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">perpendicular</span></span><span class="sig-seperator">([</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} [result] </dt><dd><span class="markdown"><p>一个可选参数，用于保存结果</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 垂直的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-scale"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.scale()</h2><span class="markdown"><p>使用传入的数量（s）缩放这个向量。如果 scalarY 被省略，则 scalarX 用于两个轴。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">scale</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Number</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Number} scalarX </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Number} [scalarY] </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 缩放后的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-scaleToMagnitude"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.scaleToMagnitude()</h2><span class="markdown"><p>对这个向量进行缩放，使它的新值等于传递的值。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">scaleToMagnitude</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Number} mag </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 缩放后的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-setValues"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.setValues()</h2><span class="markdown"><p>用一个传递的向量或一对数字来设置这个向量的值。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">setValues</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">setValues</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Number</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Number|Vector2D} x </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Number} y </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 设置后的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-subtract"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.subtract()</h2><span class="markdown"><p>将传递的向量从这个向量中减去。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">subtract</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">)</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} vecRH </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{vector2D} 减去后的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-toString"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.toString()</h2><span class="markdown"><p>返回这个向量的字符串表示。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{String} </span><span class="sig-noun">toString</span></span><span class="sig-seperator">()</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{String}</p>
</span></dd></dl></div></div><div class="doclet" id="-translate"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.translate()</h2><span class="markdown"><p>通过传递的数量转换(移动)这个向量。如果省略了dy，那么dx就被用于两个轴。</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">translate</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Number</span></span><span class="sig-seperator">[,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Number</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Number} dx </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Number} [dy] </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 转换后的向量</p>
</span></dd></dl></div></div><div class="doclet" id="-tripleProduct"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.tripleProduct()</h2><span class="markdown"><p>计算三个向量的三重积。三重向量积=b(a•c)-a(b•c)</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">{Vector2D} </span><span class="sig-noun">tripleProduct</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-noun"></span></span><span class="sig-seperator">[</span><span class="sig-phrase"><span class="sig-noun">Vector2D</span></span><span class="sig-seperator">])</span><span class="sig-phrase"><span class="sig-noun">;</span></span></code><dl class="parameter"><dt> {Vector2D} a </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Vector2D} b </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Vector2D} c </dt><dd><span class="markdown"></span></dd></dl><dl class="parameter"><dt> {Vector2D} [result] </dt><dd><span class="markdown"><p>可选参数，用于保存结果</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>{Vector2D} 三重积作为一个新矢量</p>
</span></dd></dl></div></div></div></div></div></div>
			
		</div>
	</div>
	<div class="clearer"></div>
	<div id="footer">
		<div id="contact">
			<a href="https://groups.google.com/forum/#!forum/craftyjs">
				<img src="../images/google.png">
				google groups</a>
			<a href="mailto:starwed@gmail.com">
				<img src="../images/email.png">
				starwed@gmail.com</a>
			<a href="https://github.com/craftyjs/Crafty">
				<img src="../images/github.png">
				github</a>
		</div>
		<ul>
			<li><a href="../">首页</a></li>
				<li><a href="../getting-started/">快速开始</a></li>
				<li><a href="../documentation/">文档</a></li>
				<li><a href="../api/">API</a></li>
				<li><a href="../components/">组件</a></li>
				<li class="emph"><a href="../#install">下载</a></li>
		</ul>
		<p>
			© Crafty 2010-2015. Crafty is distributed under the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT License</a>.
		</p>
	</div>
</div>


</body></html>